$(function(){
		/*初始化表格*/
		$('#planeOrg').datagrid({
    		url:'backplaneorgjson',
    		collapsible:true,
    		fit:true,
			fitColumns:true,
			toolbar:'#footer',
			pagination:true,
			pageSize:20,
			pageList:[20,50,100,200],
			remoteSort:false,
   			columns:[[
   			 	{field:'ck',checkbox:true},
   			 	{field:'orgID',hidden:'true'},
			{field:'orgName',title:'航空公司名称',align:'center',width:'20%'},
				{field:'name',title:'联系人',align:'center',width:'20%'},
				{field:'tel',title:'联系电话',align:'center',width:'20%'},
				{field:'spare1',hidden:'true'},
				{field:'memo',title:'备注',align:'center',width:'38%'}
    		]]
		});
			
});

/*搜索*/
function searchPlaneOrg(){
	
		
	var orgName = $("#searchPlaneOrgName").val(); 
		var name = $("#searchName").val(); 
		var tel = $("#searchTel").val();
		$("#planeOrg").datagrid("load",{
			orgName:orgName,
			name:name,
			tel:tel
		})
	}
	
/*清空*/
function clearPlaneOrg(){
        $("#searchPlaneOrgName").val('');
		$("#searchName").val('');
	$("#searchTel").val('');
     }
//后台	招标新建与修改时正则验证 2020.11.19
function planeOrgSubmit(planeOrgForm){
if(!(/^1[3456789]\d{9}$/.test(planeOrgForm.Tel.value))){
	$.messager.alert('错误','联系人手机号格式错误！','error'); 
	planeOrgForm.Tel.focus();
	return false;	
    } 
	}
// 修改航空公司  hanxl 2021.03.17
function updatePlaneOrg() {
	
		var rows = $('#planeOrg').datagrid('getSelections');
		var checkNum = rows.length;
		if(checkNum==0){
			$.messager.alert('错误','至少选择一项','error');
		 } else if(checkNum>1){
			$.messager.alert('错误','最多选择一项','error');
		 }else{
			//判断创建人所属公司是否相同  登陆人与创建人公司相同
			var travelOrgID = rows[0].spare1;
			var sessionOrgID=$("#sessionOrgID").val();
			if(parseInt(travelOrgID)==parseInt(sessionOrgID)){
		$.messager.confirm('Confirm', '确定要修改吗?', function(r){
	if (r){
		var iOrgID = rows[0].orgID; 
		 	location.href="/mmy/toupdateplaneorg?iOrgID="+iOrgID;
	}
});
			
	
	}else{
		$.messager.alert('错误','无法修改','error');
		
	}
		 }

}

// 删除航空公司  hanxl 2021.03.17   不正确等待修改
function delPlaneOrg() {
	
	
	var rows = $('#planeOrg').datagrid('getSelections');
		var checkNum = rows.length;
		if(checkNum==0){
			$.messager.alert('错误','至少选择一项','error');
		 }else{
			var checklist = new Array();
			var checkName = [];
			checkName.push('将要删除以下航空公司');
			for(var i=0; i<rows.length; i++){
				
				checklist.push(rows[i].OrgID);
				checkName.push('<span>'+rows[i].OrgName +'</span>');
			}
			$.messager.confirm('提示',checkName, function(r){
    		if (r){
				$.ajax({
			        url:"/mmy/deletesurroudingchecked",
			        type:"post",
			        data:{
			            checkList:checklist.toString()
			        },
			        dataType:"text",
			       success:function () {
						 $("#dg").datagrid("reload");
			             $.messager.show({title:'消息',msg:'删除成功',timeout:3000,});
					},
			        error:function () {
			           $.messager.show({title:'消息',msg:'删除失败',timeout:3000,});
			        }
			    })
    		}
		});		
	}
	
	
	
	var checkNum = $("input[name='ckone']:checked").length;

	if (checkNum == 0) {
		alert("至少选择一项");
		return;
	} else {

		if (confirm("确定要删除吗？")) {
			var checklist = new Array();
			$("input[name='ckone']:checked").each(function() {
				checklist.push($(this).val());
			});
		}

		$.ajax({
			url : "/mmy/delplaneorg",
			type : "post",
			data : {
				checkList : checklist.toString()
			},
			dataType : "text",
			success : function(data) {
				location.reload();
				alert("删除成功！")

			},
			error : function(msg) {
				alert("删除失败！")
			}
		})
	}

}



